<!DOCTYPE html>
<html>
<head>
    <title>管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <!-- <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" placeholder="搜索标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form> -->
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <#if shiro.hasPermission("kaijie:outcheck:save")>
        <button class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加 </button>
        </#if>
    </div>
</script>

<script type="text/html" id="currentTableTypeTpl">
    {{# layui.each(d.label, function(index, item){ }}
    <span class="layui-badge-rim">{{item}}</span>
    {{# }); }}
</script>
<script type="text/html" id="currentTableGenderTpl">
    {{# if(d.gender == 1){ }}
    <span class="layui-badge layui-bg-green">男</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-green">女</span>
    {{# } }}
</script>
<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("kaijie:outcheck:save")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </#if>
    <#if shiro.hasPermission("kaijie:outcheck:delete")>
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </#if>
</script>

<script>
    var formDataId = 0;
    layui.use(['form','table'], function () {
        var $ = layui.jquery,
        	form = layui.form,
            table = layui.table;

        tableSearch({},'kaijie/outcheck/list');
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                formDataId = 0;
                openFormView('house/out_check/form.html', '添加');

            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('house/out_check/form.html', '编辑');
                return false;
            }else if (obj.event === 'delete') {
                layer.confirm('确定删除 '+data.name+' 吗？', function (index) {
                    deleteTableRow('kaijie/outcheck/delete/', [data.id], function (rs) {
                    	obj.del();
                    });
                    layer.close(index);
                });
            }
        });
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                 toolbar: '#toolbarDemo',
                defaultToolbar: [],
                cols: [[
                    //{type: "numbers", width: 80},
                    //{field: 'id', minWidth: 80, title: 'id'},
                    {field: 'rmid', minWidth: 80, title: '房间号'},
                    {field: 'name', minWidth: 80, title: '入住人登记人姓名' },
                    {field: 'cardid', minWidth: 80, title: '身份证'},
                    {field: 'money', minWidth: 80, title: '实收押金'},
                    {field: 'roomMoney', minWidth: 80, title: '实收房费'},
                    {field: 'intoTime', minWidth: 80, title: '入住时间'},
                    {field: 'outTime', minWidth: 80, title: '离开时间'},
                    {field: 'dayCount', minWidth: 80, title: '入住天数'},
                    {field: 'manCount', minWidth: 80, title: '入住人数'},
                    {field: 'otherMoney', minWidth: 80, title: '计算额外消费'},
                    {field: 'cutMoney', minWidth: 80, title: '押金扣除'},
                    {field: 'cutReason', minWidth: 80, title: '押金扣除原因'},
                    {field: 'useState', minWidth: 80, title: '使用状态'},
                    {title: '操作', width: 160, toolbar: '#currentTableBar', align: "center"}
                    
                ]],
                limits: [10, 15, 20, 25],
                limit: 10,
                page: true
            });
        	return tablethis;
        };
        // 监听搜索操作
        form.on('submit(form-search-btn)', function (data) {
            //执行搜索重载
            if (data.field.title) {
            	tableSearch({"title":data.field.title},'video/package/search');
            //table.filterData(data.field.title);
	        } else {
	            tableSearch({},'bb/list');
	            //table.clearFilter();
	        }
	        return false;
	    });
        form.on('submit(form-reset-btn)', function (data) {
            tableSearch({},'bb/list');
            $("#searchForm")[0].reset();
            //table.clearFilter();
            return false;
        });
    });
</script>

</body>
</html>